home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / ixemul / sdk / man / cat5 / a.out.0 next >
Encoding:
Text File  |  1998-06-15  |  16.4 KB  |  325 lines

  1.  
  2. A.OUT(5)                   UNIX Programmer's Manual                   A.OUT(5)
  3.  
  4. NNAAMMEE
  5.      aa..oouutt - format of executable binary files
  6.  
  7. SSYYNNOOPPSSIISS
  8.      ##iinncclluuddee <<aa..oouutt..hh>>
  9.  
  10. DDEESSCCRRIIPPTTIIOONN
  11.      The include file <_a_._o_u_t_._h> declares three structures and several macros.
  12.      The structures describe the format of executable machine code files
  13.      (`binaries') on the system.
  14.  
  15.      A binary file consists of up to 7 sections.  In order, these sections
  16.      are:
  17.  
  18.      exec header       Contains parameters used by the kernel to load a binary
  19.                        file into memory and execute it, and by the link editor
  20.                        ld(1) to combine a binary file with other binary files.
  21.                        This section is the only mandatory one.
  22.  
  23.      text segment      Contains machine code and related data that are loaded
  24.                        into memory when a program executes.  May be loaded
  25.                        read-only.
  26.  
  27.      data segment      Contains initialized data; always loaded into writable
  28.                        memory.
  29.  
  30.      text relocations  Contains records used by the link editor to update
  31.                        pointers in the text segment when combining binary
  32.                        files.
  33.  
  34.      data relocations  Like the text relocation section, but for data segment
  35.                        pointers.
  36.  
  37.      symbol table      Contains records used by the link editor to cross ref-
  38.                        erence the addresses of named variables and functions
  39.                        (`symbols') between binary files.
  40.  
  41.      string table      Contains the character strings corresponding to the
  42.                        symbol names.
  43.  
  44.      Every binary file begins with an _e_x_e_c structure:
  45.  
  46.            struct exec {
  47.                    unsigned long   a_midmag;
  48.                    unsigned long   a_text;
  49.                    unsigned long   a_data;
  50.                    unsigned long   a_bss;
  51.                    unsigned long   a_syms;
  52.                    unsigned long   a_entry;
  53.                    unsigned long   a_trsize;
  54.                    unsigned long   a_drsize;
  55.            };
  56.  
  57.      The fields have the following functions:
  58.  
  59.      _a___m_i_d_m_a_g  This field is stored in network byte-order so that binaries for
  60.                for machines with alternate byte orders can be distinguished.
  61.                It has a number of sub-components accessed by the macros
  62.                N_GETFLAG(), N_GETMID(), and N_GETMAGIC(), and set by the macro
  63.                N_SETMAGIC().
  64.  
  65.  
  66.  
  67.                The macro N_GETFLAG() returns a few flags:
  68.  
  69.                EX_DYNAMIC  indicates that the executable requires the services
  70.                            of the run-time link editor.
  71.  
  72.                EX_PIC      indicates that the object contains position inde-
  73.                            pendent code. This flag is set by as(1) when given
  74.                            the `-k' flag and is preserved by ld(1) if neces-
  75.                            sary.
  76.  
  77.                If both EX_DYNAMIC and EX_PIC are set, the object file is a po-
  78.                sition indendent executable image (eg. a shared library), which
  79.                is to be loaded into the process address space by the run-time
  80.                link editor.
  81.  
  82.                The macro N_GETMID() returns the machine-id.  This indicates
  83.                which machine(s) the binary is intended to run on.
  84.  
  85.                N_GETMAGIC() specifies the magic number, which uniquely identi-
  86.                fies binary files and distinguishes different loading conven-
  87.                tions.  The field must contain one of the following values:
  88.  
  89.                OMAGIC  The text and data segments immediately follow the head-
  90.                        er and are contiguous.  The kernel loads both text and
  91.                        data segments into writable memory.
  92.  
  93.                NMAGIC  As with OMAGIC, text and data segments immediately fol-
  94.                        low the header and are contiguous.  However, the kernel
  95.                        loads the text into read-only memory and loads the data
  96.                        into writable memory at the next page boundary after
  97.                        the text.
  98.  
  99.                ZMAGIC  The kernel loads individual pages on demand from the
  100.                        binary.  The header, text segment and data segment are
  101.                        all padded by the link editor to a multiple of the page
  102.                        size.  Pages that the kernel loads from the text seg-
  103.                        ment are read-only, while pages from the data segment
  104.                        are writable.
  105.  
  106.      _a___t_e_x_t    Contains the size of the text segment in bytes.
  107.  
  108.      _a___d_a_t_a    Contains the size of the data segment in bytes.
  109.  
  110.      _a___b_s_s     Contains the number of bytes in the `bss segment' and is used
  111.                by the kernel to set the initial break (brk(2))  after the data
  112.                segment.  The kernel loads the program so that this amount of
  113.                writable memory appears to follow the data segment and initial-
  114.                ly reads as zeroes.
  115.  
  116.      _a___s_y_m_s    Contains the size in bytes of the symbol table section.
  117.  
  118.      _a___e_n_t_r_y   Contains the address in memory of the entry point of the pro-
  119.                gram after the kernel has loaded it; the kernel starts the exe-
  120.                cution of the program from the machine instruction at this ad-
  121.                dress.
  122.  
  123.      _a___t_r_s_i_z_e  Contains the size in bytes of the text relocation table.
  124.  
  125.      _a___d_r_s_i_z_e  Contains the size in bytes of the data relocation table.
  126.  
  127.      The _a_._o_u_t_._h include file defines several macros which use an _e_x_e_c struc-
  128.      ture to test consistency or to locate section offsets in the binary file.
  129.  
  130.      NN__BBAADDMMAAGG(_e_x_e_c)  Nonzero if the _a___m_a_g_i_c field does not contain a recog-
  131.  
  132.                      nized value.
  133.  
  134.      NN__TTXXTTOOFFFF(_e_x_e_c)  The byte offset in the binary file of the beginning of
  135.                      the text segment.
  136.  
  137.      NN__SSYYMMOOFFFF(_e_x_e_c)  The byte offset of the beginning of the symbol table.
  138.  
  139.      NN__SSTTRROOFFFF(_e_x_e_c)  The byte offset of the beginning of the string table.
  140.  
  141.      Relocation records have a standard format which is described by the
  142.      _r_e_l_o_c_a_t_i_o_n___i_n_f_o structure:
  143.  
  144.            struct relocation_info {
  145.                    int             r_address;
  146.                    unsigned int    r_symbolnum : 24,
  147.                                    r_pcrel : 1,
  148.                                    r_length : 2,
  149.                                    r_extern : 1,
  150.                                    r_baserel : 1,
  151.                                    r_jmptable : 1,
  152.                                    r_relative : 1,
  153.                                    r_copy : 1;
  154.            };
  155.  
  156.      The _r_e_l_o_c_a_t_i_o_n___i_n_f_o fields are used as follows:
  157.  
  158.      _r___a_d_d_r_e_s_s    Contains the byte offset of a pointer that needs to be link-
  159.                   edited.  Text relocation offsets are reckoned from the start
  160.                   of the text segment, and data relocation offsets from the
  161.                   start of the data segment.  The link editor adds the value
  162.                   that is already stored at this offset into the new value
  163.                   that it computes using this relocation record.
  164.  
  165.      _r___s_y_m_b_o_l_n_u_m  Contains the ordinal number of a symbol structure in the
  166.                   symbol table (it is _n_o_t a byte offset).  After the link edi-
  167.                   tor resolves the absolute address for this symbol, it adds
  168.                   that address to the pointer that is undergoing relocation.
  169.                   (If the _r___e_x_t_e_r_n bit is clear, the situation is different;
  170.                   see below.)
  171.  
  172.      _r___p_c_r_e_l      If this is set, the link editor assumes that it is updating
  173.                   a pointer that is part of a machine code instruction using
  174.                   pc-relative addressing.  The address of the relocated point-
  175.                   er is implicitly added to its value when the running program
  176.                   uses it.
  177.  
  178.      _r___l_e_n_g_t_h     Contains the log base 2 of the length of the pointer in
  179.                   bytes; 0 for 1-byte displacements, 1 for 2-byte displace-
  180.                   ments, 2 for 4-byte displacements.
  181.  
  182.      _r___e_x_t_e_r_n     Set if this relocation requires an external reference; the
  183.                   link editor must use a symbol address to update the pointer.
  184.                   When the _r___e_x_t_e_r_n bit is clear, the relocation is `local';
  185.                   the link editor updates the pointer to reflect changes in
  186.                   the load addresses of the various segments, rather than
  187.                   changes in the value of a symbol (except when _r___b_a_s_e_r_e_l is
  188.                   also set (see below).  In this case, the content of the
  189.                   _r___s_y_m_b_o_l_n_u_m field is an _n___t_y_p_e value (see below); this type
  190.                   field tells the link editor what segment the relocated
  191.                   pointer points into.
  192.  
  193.      _r___b_a_s_e_r_e_l    If set, the symbol, as identified by the _r___s_y_m_b_o_l_n_u_m field,
  194.                   is to be relocated to an offset into the Global Offset
  195.                   Table.  At run-time, the entry in the Global Offset Table at
  196.  
  197.  
  198.                   this offset is set to be the address of the symbol.
  199.  
  200.      _r___j_m_p_t_a_b_l_e   If set, the symbol, as identified by the _r___s_y_m_b_o_l_n_u_m field,
  201.                   is to be relocated to an offset into the Procedure Linkage
  202.                   Table.
  203.  
  204.      _r___r_e_l_a_t_i_v_e   If set, this relocation is relative to the (run-time) load
  205.                   address of the image this object file is going to be a part
  206.                   of. This type of relocation only occurs in shared objects.
  207.  
  208.      _r___c_o_p_y       If set, this relocation record identifies a symbol whose
  209.                   contents should be copied to the location given in
  210.                   _r___a_d_d_r_e_s_s_. The copying is done by the run-time link-editor
  211.                   from a suitable data item in a shared object.
  212.  
  213.      Symbols map names to addresses (or more generally, strings to values).
  214.      Since the link-editor adjusts addresses, a symbol's name must be used to
  215.      stand for its address until an absolute value has been assigned.  Symbols
  216.      consist of a fixed-length record in the symbol table and a variable-
  217.      length name in the string table.  The symbol table is an array of _n_l_i_s_t
  218.      structures:
  219.  
  220.            struct nlist {
  221.                    union {
  222.                            char    *n_name;
  223.                            long    n_strx;
  224.                    } n_un;
  225.                    unsigned char   n_type;
  226.                    char            n_other;
  227.                    short           n_desc;
  228.                    unsigned long   n_value;
  229.            };
  230.  
  231.      The fields are used as follows:
  232.  
  233.      _n___u_n_._n___s_t_r_x  Contains a byte offset into the string table for the name of
  234.                   this symbol.  When a program accesses a symbol table with
  235.                   the nlist(3) function, this field is replaced with the
  236.                   _n___u_n_._n___n_a_m_e field, which is a pointer to the string in memo-
  237.                   ry.
  238.  
  239.      _n___t_y_p_e       Used by the link editor to determine how to update the sym-
  240.                   bol's value.  The _n___t_y_p_e field is broken down into three
  241.                   sub-fields using bitmasks.  The link editor treats symbols
  242.                   with the N_EXT type bit set as `external' symbols and per-
  243.                   mits references to them from other binary files.  The N_TYPE
  244.                   mask selects bits of interest to the link editor:
  245.  
  246.                   N_UNDF  An undefined symbol.  The link editor must locate an
  247.                           external symbol with the same name in another binary
  248.                           file to determine the absolute value of this symbol.
  249.                           As a special case, if the _n___v_a_l_u_e field is nonzero
  250.                           and no binary file in the link-edit defines this
  251.                           symbol, the link-editor will resolve this symbol to
  252.                           an address in the bss segment, reserving an amount
  253.                           of bytes equal to _n___v_a_l_u_e. If this symbol is unde-
  254.                           fined in more than one binary file and the binary
  255.                           files do not agree on the size, the link editor
  256.                           chooses the greatest size found across all binaries.
  257.  
  258.                   N_ABS   An absolute symbol.  The link editor does not update
  259.                           an absolute symbol.
  260.  
  261.                   N_TEXT  A text symbol.  This symbol's value is a text ad-
  262.                           dress and the link editor will update it when it
  263.  
  264.                           merges binary files.
  265.  
  266.                   N_DATA  A data symbol; similar to N_TEXT but for data ad-
  267.                           dresses.  The values for text and data symbols are
  268.                           not file offsets but addresses; to recover the file
  269.                           offsets, it is necessary to identify the loaded ad-
  270.                           dress of the beginning of the corresponding section
  271.                           and subtract it, then add the offset of the section.
  272.  
  273.                   N_BSS   A bss symbol; like text or data symbols but has no
  274.                           corresponding offset in the binary file.
  275.  
  276.                   N_FN    A filename symbol.  The link editor inserts this
  277.                           symbol before the other symbols from a binary file
  278.                           when merging binary files.  The name of the symbol
  279.                           is the filename given to the link editor, and its
  280.                           value is the first text address from that binary
  281.                           file.  Filename symbols are not needed for link-
  282.                           editing or loading, but are useful for debuggers.
  283.  
  284.                   The N_STAB mask selects bits of interest to symbolic debug-
  285.                   gers such as gdb(1);  the values are described in stab(5).
  286.  
  287.      _n___o_t_h_e_r      This field provides information on the nature of the symbol
  288.                   independent of the symbol's location in terms of segments as
  289.                   determined by the _n___t_y_p_e field. Currently, the lower 4 bits
  290.                   of the _n___o_t_h_e_r field hold one of two values: AUX_FUNC and
  291.                   AUX_OBJECT (see <_l_i_n_k_._h> for their definitions). AUX_FUNC
  292.                   associates the symbol with a callable function, while
  293.                   AUX_OBJECT associates the symbol with data, irrespective of
  294.                   their locations in either the text or the data segment.
  295.                   This field is intended to be used by ld(1) for the construc-
  296.                   tion of dynamic executables.
  297.  
  298.      _n___d_e_s_c       Reserved for use by debuggers; passed untouched by the link
  299.                   editor.  Different debuggers use this field for different
  300.                   purposes.
  301.  
  302.      _n___v_a_l_u_e      Contains the value of the symbol.  For text, data and bss
  303.                   symbols, this is an address; for other symbols (such as de-
  304.                   bugger symbols), the value may be arbitrary.
  305.  
  306.      The string table consists of an _u_n_s_i_g_n_e_d _l_o_n_g length followed by null-
  307.      terminated symbol strings.  The length represents the size of the entire
  308.      table in bytes, so its minimum value (or the offset of the first string)
  309.      is always 4 on 32-bit machines.
  310.  
  311. SSEEEE AALLSSOO
  312.      as(1),  gdb(1),  ld(1),  brk(2),  execve(2),  nlist(3),  core(5),
  313.      dbx(5),  stab(5),  link(5)
  314.  
  315. HHIISSTTOORRYY
  316.      The _a_._o_u_t_._h include file appeared in Version 7 AT&T UNIX.
  317.  
  318. BBUUGGSS
  319.      Nobody seems to agree on what _b_s_s stands for.
  320.  
  321.      New binary file formats may be supported in the future, and they probably
  322.      will not be compatible at any level with this ancient format.
  323.  
  324. BSD Experimental                 June 5, 1993                                5
  325.